package com.kaoshidian.front.mongodb.base;

import java.net.UnknownHostException;
import java.util.Set;

import org.huntaway.mongodb.MongodbUtil;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public abstract class BaseManage {
	protected static MongodbUtil mongUtil = new MongodbUtil();

	public abstract void treate(DBCollection coll);

	public void mainBody(String collectionName) {
		Mongo m;
		try {
			m = new Mongo("localhost", 27017);
			DB db = m.getDB("ksd");
			Set<String> colls = db.getCollectionNames();
			for (String s : colls) {
				System.out.println(s);
			}
			DBCollection coll = db.getCollection(collectionName);
			treate(coll);
			DBCursor cur = coll.find();
			while (cur.hasNext()) {
				System.out.println(cur.next());
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MongoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
